<template>
	<view class="content">
		<u-swipe-action v-if="isnotdelete(item.id)" :show="item.show" :index="index" v-for="(item, index) in list"
			:key="item.id" @click="click(item)" @open="open" :options="options">
			<view style="display: flex;width: 100%;margin-bottom: 15rpx;">
				<view
					style="width: 150rpx;height: 150rpx;margin: 10rpx; display: flex;flex-direction: column;padding: 10rpx;background: #f7f7f7;justify-content: center;">
					<view style="font-weight: bold;font-size: 40rpx;">
						{{$u.timeFormat(item.time, 'mm.dd')}}
					</view>
					<view style="font-size: 26rpx;margin-top: 15rpx;">
						{{$u.timeFormat(item.time, 'yyyy')}}
					</view>
				</view>
				<view style="display: flex;flex-direction: column;flex:1;margin: 5rpx;">
					<view style="font-size: 28rpx;width: 100%;" class="u-line-2">
						{{ item.title }}
					</view>
					<view style="width: 100%;" v-if="item.images && item.images.length > 0">
						<mypyqimagesview :list="item.images" />
					</view>
				</view>
			</view>
		</u-swipe-action>
	</view>
</template>

<script>
	import mypyqimagesview from './components/mypyqimagesview.vue'
	import {
		mapState
	} from 'vuex'
	export default {
		components: {
			mypyqimagesview
		},
		data() {
			return {
				disabled: false,
				btnWidth: 180,
				show: false,
				options: [{
					text: '删除',
					style: {
						backgroundColor: '#dd524d'
					}
				}],
				dels: [],
				list:[]
			};
		},
		onLoad() {
			this.getdata()
		},
		computed: {
			...mapState({
				
			})
		},
		methods: {
			getdata:async function(){
				const user = this.$store.state.user.user
				const ret = await this.$u.post(`bgyx/bgyx/getdata/pyqinfo`,{
					where:{uid:user.id},
					order:{time:'desc'}
				})
				if(ret && ret.success && ret.data){
					this.list = ret.data.map(e=>{
						const images = JSON.parse(e.images)
						return {
							...e,
							images
						}
					})
				}
				
			},
			isnotdelete: function(id) {
				if (this.dels.includes(id)) {
					return false
				} else {
					return true
				}
			},
			async click(item) {
				console.log(item)
				await this.$u.delete(`friend/friend/delpyqinfo/${item.id}`)
				this.dels.push(item.id)
				this.list = this.list.filter(e=>e.id != item.id)
			},
			// 如果打开一个的时候，不需要关闭其他，则无需实现本方法
			open(index) {
				console.log(11223, index)
				// 先将正在被操作的swipeAction标记为打开状态，否则由于props的特性限制，
				// 原本为'false'，再次设置为'false'会无效
				this.list[index].show = true;
				this.list.map((val, idx) => {
					if (index != idx) this.list[idx].show = false;
				})
			}
		}
	};
</script>

<style scoped>
	.content {
		width: 100%;
		padding: 15rpx;
		display: flex;
		flex-direction: column;
		height: 100vh;
		background: white;
	}
</style>